package com.test.spring2025_3_31.Controller;

import com.test.spring2025_3_31.Constants.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("producer")
public class rabbitMQController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @RequestMapping("work")
    public void work() {
        for (int i = 0; i < 10; i++) {
            rabbitTemplate.convertAndSend("", Constants.WORK_QUEUE, "hello rabbitMQ..." + i);
        }
        log.info("消息发送完毕...");
    }

    @RequestMapping("fanout")
    public void fanout(){
        for (int i = 0; i < 4; i++) {
            rabbitTemplate.convertAndSend(Constants.FANOUT_EXCHANGE,"","hello rabbit fanout");
        }
        log.info("发送完毕...");
    }

    @RequestMapping("direct")
    public void direct(String routingKey){
        rabbitTemplate.convertAndSend(Constants.DIRECT_EXCHANGE,routingKey,"hello rabbitMQ direct...");
        log.info("发送完毕...");
    }

    @RequestMapping("topic")
    public void topic(String routingKey){
        rabbitTemplate.convertAndSend(Constants.TOPIC_EXCHANGE, routingKey, "hello rabbit topic....");
        log.info("发送完毕...");
    }

}
